package cc.rboot.limit.grouper;

import cc.rboot._core.holder.AppContextHolder;
import cc.rboot.limit.core.AbstractAccessLimitGrouper;
import cc.rboot.token.core.ITokenAware;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 如果使用这个分类器，必须实现ITokenAware接口，并用@Component标记实现类
 */
public class OverallTokenAccessLimitGrouper extends AbstractAccessLimitGrouper {

    @Override
    public String grouper(ProceedingJoinPoint joinPoint) throws Exception {
        ITokenAware tokenAware = AppContextHolder.getBean(ITokenAware.class);
        if (tokenAware == null) {
            throw new Exception("必须实现ITokenAware接口才能使用分组器：OverallTokenAccessLimitGrouper");
        }
        return tokenAware.token();
    }
}
